<template>
  <el-form
    class="formItem demo-ruleForm"
    :model="ruleForm"
    status-icon
    :rules="rules"
    ref="ruleForm"
    label-width="100px"
  >
    <el-form-item label="账号" prop="account">
      <el-input
        type="text"
        v-model="ruleForm.account"
        autocomplete="off"
      ></el-input>
    </el-form-item>

    <el-form-item label="密码" prop="password">
      <el-input v-model.number="ruleForm.password" type="password"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button @click="toHome()">登录</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      ruleForm: {
        account: "",
        password: "",
      },
      rules: {
        account: [
          { required: true, message: "请输入账号", trigger: "blur" },
          { min: 3, max: 6, message: "长度在 3 到 6 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 6, message: "长度在 3 到 6 个字符", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    toHome() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          // alert("submit!");
          this.$router.push("/home");
        } else {
          this.$message("账号或者密码格式不正确");

          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style scoped>
.skiptohome {
  color: white;
  width: 200px;
  height: 50px;
  background: darkslateblue;
}
.formItem {
  width: 300px;
  height: 300px;
  display: block;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
</style>
